const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
 
// Connection URL
const url = 'mongodb://localhost:27017'
 
// Database Name
const dbName = 'gp20'
 
// Use connect method to connect to the server
function connect() {
  return new Promise((resolve, reject) => {
    MongoClient.connect(url, {useUnifiedTopology: true}, function(err, client) {
      assert.equal(null, err)
      console.log("Connected successfully to server")
     
      const db = client.db(dbName)

      // 在这做数据库的操作

      resolve({
        db,
        client
      })
    })
  })
}

module.exports = connect